// app/controller/news.js
const Controller = require('egg').Controller

class NewsController extends Controller {
    async list() {
        const ctx = this.ctx
        const page = ctx.query.page || 1
        const newsList = await ctx.service.news.list(page)
        await ctx.render('news/list.html', { list: newsList })
    }
    async detail() {
        const ctx = this.ctx
        const newsData = await ctx.service.news.getNewsDetail(ctx.params.id)
        await ctx.render('news/newsdetail.html', {
            newsDetail: newsData.document,
            newsAd: newsData.ad
        })
    }
    async search() {
        const ctx = this.ctx 
        await ctx.render('news/searchnews.html')
    }
}

module.exports = NewsController